/***************************************************************
 *
 * (c) 2008 Markus Dittrich 
 *
 * This program is free software; you can redistribute it 
 * and/or modify it under the terms of the GNU General Public 
 * License Version 3 as published by the Free Software Foundation. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License Version 3 for more details.
 *
 * You should have received a copy of the GNU General Public 
 * License along with this program; if not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA 02111-1307, USA.
 *
 ****************************************************************/

/* Qt includes */
#include <QCheckBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
#include <QVBoxLayout>

/* local includes */
#include "basic_definitions.h"
#include "settings_widget.h"



/****************************************************************
 *
 * public member functions
 *
 ***************************************************************/

//---------------------------------------------------------------
// constructor 
//---------------------------------------------------------------
SettingsWidget::SettingsWidget(Settings& settings, QWidget* myParent)
  :
    QWidget(myParent),
    settings_(settings)
{
  status_ = SUCCESSFULLY_CONSTRUCTED;
}


//---------------------------------------------------------------
// main init function 
//---------------------------------------------------------------
bool SettingsWidget::Init()
{
  if ( status_ != SUCCESSFULLY_CONSTRUCTED )
  {
    return false;
  }

  setWindowTitle(tr("settings"));
  
  generate_sensitivity_grouper_();
  generate_continuous_data_info_grouper_();

  /* add all widgets to main layout */
  QVBoxLayout* mainLayout = new QVBoxLayout;
  mainLayout->addWidget(continuousDataInfoSelector_);
  mainLayout->addWidget(sensitivityWidgetGrouper_);
 
  /* generate ok button */
  QHBoxLayout* buttonLayout = new QHBoxLayout;
  QPushButton* okButton = new QPushButton(tr("ok"));
  buttonLayout->addStretch(1);
  buttonLayout->addWidget(okButton);
  mainLayout->addStretch(1);
  mainLayout->addLayout(buttonLayout);

  setLayout(mainLayout);

  connect(okButton,SIGNAL(clicked()),this,SLOT(close()));

  return true;
}


//--------------------------------------------------------------
// generate the widget for selecting the data selection 
// sensitivity on the canvas
//--------------------------------------------------------------
void SettingsWidget::generate_sensitivity_grouper_()
{
  sensitivityWidgetGrouper_ = new QGroupBox(
      tr("change canvas selection sensitvity"));
  QVBoxLayout* sensitivityWidgetLayout = new QVBoxLayout;
  
  QSlider* mainSlider = new QSlider;
  mainSlider->setOrientation(Qt::Horizontal);
  mainSlider->setTickPosition(QSlider::TicksAbove);
  mainSlider->setTickInterval(1);
  mainSlider->setPageStep(1);
  mainSlider->setMinimum(0);
  mainSlider->setMaximum(2);
  int currentSetting = 
    settings_.get_canvas_data_selection_sensitivity();
  mainSlider->setSliderPosition(currentSetting);
 
  sensitivityWidgetLayout->addWidget(mainSlider);
  sensitivityWidgetGrouper_->setLayout(sensitivityWidgetLayout);

  connect(mainSlider,SIGNAL(valueChanged(int)),&settings_,
      SLOT(set_canvas_data_selection_sensitivity(int)));
}
 


//--------------------------------------------------------------
// generate the widget for selecting continuous data info
// display when moving the mouse over the canvas
//--------------------------------------------------------------
void SettingsWidget::generate_continuous_data_info_grouper_()
{
  continuousDataInfoSelector_ = 
    new QCheckBox(tr("show continuous data info"));
  bool state = settings_.get_continuous_data_info();
  continuousDataInfoSelector_->setChecked(state);

  connect(continuousDataInfoSelector_,SIGNAL(clicked(bool)),
      &settings_,SLOT(set_continuous_data_info(bool)));
}


